<template>
	<view class="jnpf-wrap jnpf-wrap-workflow">
		<u-form :model="info" ref="dataForm" :errorType="['toast']" label-position="left" label-width="150"
			label-align="left">
			<u-form-item label="版本" v-if="judgeShow('wa002')">
				<u-input v-model="info.wa005" placeholder="版本" disabled></u-input>
			</u-form-item>
			<u-form-item label="客户名称" v-if="judgeShow('wa004')">
				<u-input v-model="info.wa004" placeholder="客户名称" :disabled="judgeWrite('wa004')"></u-input>
			</u-form-item>
			<u-form-item label="销售机会编号" v-if="judgeShow('wa010')">
				<u-input v-model="info.wa010" placeholder="销售机会编号" :disabled="judgeWrite('wa010')"></u-input>
			</u-form-item>
			<u-form-item label="行业类型" type="textarea" v-if="judgeShow('wa020')">
				<u-input v-model="info.wa020" placeholder="行业类型" :disabled="judgeWrite('wa020')"></u-input>
			</u-form-item>
			<u-form-item label="售前负责人" type="textarea" v-if="judgeShow('wa013')">
				<view v-for="(item,index) in wa013Name" :key="index" style="margin-left: 5px;">
					<u-tag :text="item" type="success" />
				</view>
			</u-form-item>
			<u-form-item label="业务负责人" type="textarea" v-if="judgeShow('wa014')">
				<view v-for="(item,index) in wa014Name" :key="index" style="margin-left: 5px;">
					<u-tag :text="item" type="success" />
				</view>
			</u-form-item>
			<u-form-item label="编写/日期" type="textarea" v-if="judgeShow('wa015')">
				<u-input v-model="info.wa015" placeholder="编写/日期" :disabled="judgeWrite('wa015')"></u-input>
			</u-form-item>
			<u-form-item label="需求日期" type="textarea" v-if="judgeShow('wa023')">
				<u-input v-model="info.wa023" placeholder="需求日期" :disabled="judgeWrite('wa023')"></u-input>
			</u-form-item>
			<u-form-item label="资深工程师" type="textarea" v-if="judgeShow('wa024')">
				<u-input v-model="info.wa024" placeholder="资深工程师" :disabled="judgeWrite('wa024')"></u-input>
			</u-form-item>
			<u-form-item label="附件" v-if="judgeShow('wa019')">
				<jnpf-file v-model="info.wa019" disabled />
			</u-form-item>
			<u-form-item label="名称" v-if="judgeShow('wa002')">
				<u-input v-model="info.wa002" placeholder="名称" :disabled="judgeWrite('wa002')"></u-input>
			</u-form-item>
			<u-form-item label="规格" v-if="judgeShow('wa006')">
				<u-input v-model="info.wa006" placeholder="规格" :disabled="judgeWrite('wa006')"></u-input>
			</u-form-item>
			<u-form-item label="数量" v-if="judgeShow('wa007')">
				<u-input v-model="info.wa007" placeholder="数量" :disabled="judgeWrite('wa007')"></u-input>
			</u-form-item>
			<u-form-item label="单位" v-if="judgeShow('wa008')">
				<u-input v-model="info.wa008" placeholder="单位" :disabled="judgeWrite('wa008')"></u-input>
			</u-form-item>
			<u-form-item label="成本单价" v-if="judgeShow('wa009')">
				<u-input v-model="info.wa009" placeholder="成本单价" :disabled="judgeWrite('wa009')"></u-input>
			</u-form-item>
			<u-form-item label="成本总价" v-if="judgeShow('wa011')">
				<u-input v-model="info.wa011" placeholder="成本总价" :disabled="judgeWrite('wa011')"></u-input>
			</u-form-item>
			<u-form-item label="单价" v-if="judgeShow('wa021')">
				<u-input v-model="info.wa021" placeholder="单价" :disabled="judgeWrite('wa021')"></u-input>
			</u-form-item>
			<u-form-item label="金额" v-if="judgeShow('wa022')">
				<u-input v-model="info.wa022" placeholder="金额" :disabled="judgeWrite('wa022')"></u-input>
			</u-form-item>
			<u-form-item label="金额大写" v-if="judgeShow('wa012')">
				<u-input v-model="info.wa012" placeholder="金额大写" :disabled="judgeWrite('wa012')"></u-input>
			</u-form-item>
			<view class="jnpf-table" style="margin-top: 24rpx;">
				<view class="jnpf-table-item" style="margin-bottom: 24rpx;" v-for="(item,i) in lst" :key="i">
					<u-form-item label="序号">
						{{i+1}}
					</u-form-item>
					<u-form-item label="系统" v-if="judgeShow('tableField117-wb003')">
						<u-input v-model="item.wb003" placeholder="系统" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb003')
                        "></u-input>
					</u-form-item>
					<u-form-item label="工序" v-if="judgeShow('tableField117-wb004')">
						<u-input v-model="item.wb004" placeholder="工序" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb004')
                        "></u-input>
					</u-form-item>
					<u-form-item label="品号/工程品号" v-if="judgeShow('tableField117-wb023')">
						<u-input v-model="item.wb023" placeholder="品号/工程品号" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb023')
                        "></u-input>
					</u-form-item>
					<u-form-item label="设备名称" v-if="judgeShow('tableField117-wb005')">
						<u-input v-model="item.wb005" placeholder="设备名称" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb005')
                        "></u-input>
					</u-form-item>
					<u-form-item label="型号/规格" v-if="judgeShow('tableField117-wb006')">
						<u-input v-model="item.wb006" placeholder="型号/规格" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb006')
                        "></u-input>
					</u-form-item>
					<u-form-item label="品牌" v-if="judgeShow('tableField117-tb007')">
						<u-input v-model="item.wb007" placeholder="品牌" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-tb007')
                        "></u-input>
					</u-form-item>
					<u-form-item label="数量" v-if="judgeShow('tableField117-wb008')">
						<u-input v-model="item.wb008" placeholder="数量" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb008')
                        "></u-input>
					</u-form-item>
					<u-form-item label="单位" v-if="judgeShow('tableField117-wb009')">
						<u-input v-model="item.wb009" placeholder="单位" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb009')
                        "></u-input>
					</u-form-item>
					<u-form-item label="单价" v-if="judgeShow('tableField117-wb010')">
						<u-input v-model="item.wb010" placeholder="单价" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb010')
                        "></u-input>
					</u-form-item>
					<u-form-item label="总价" v-if="judgeShow('tableField117-wb011')">
						<u-input v-model="item.wb011" placeholder="总价" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb011')
                        "></u-input>
					</u-form-item>
					<u-form-item label="销售单价" v-if="judgeShow('tableField117-wb019')">
						<u-input v-model="item.wb019" placeholder="销售单价" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb019')
                        "></u-input>
					</u-form-item>
					<u-form-item label="销售金额" v-if="judgeShow('tableField117-wb020')">
						<u-input v-model="item.wb020" placeholder="销售金额" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb020')
                        "></u-input>
					</u-form-item>
					<u-form-item label="品号属性" v-if="judgeShow('tableField117-wb018')">
						<!-- 	<u-input v-model="item.wb018" placeholder="品号属性" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb018')
                        "></u-input> -->
						{{tb010CName(item.wb018)}}
					</u-form-item>
					<u-form-item label="参考成本单价" v-if="judgeShow('tableField117-wb022')">
						<u-input v-model="item.wb022" placeholder="参考成本单价" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb022')
                        "></u-input>
					</u-form-item>
					<u-form-item label="参考销售单价" v-if="judgeShow('tableField117-wb021')">
						<u-input v-model="item.wb021" placeholder="参考销售单价" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb021')
                        "></u-input>
					</u-form-item>
					<u-form-item label="备注" v-if="judgeShow('tableField117-wb012')">
						<u-input v-model="item.wb012" placeholder="备注" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb012')
                        "></u-input>
					</u-form-item>

					<u-form-item label="供应商名称" v-if="judgeShow('tableField117-wb013')">
						<u-input v-model="item.wb013" placeholder="供应商名称" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb013')
                        "></u-input>
					</u-form-item>

					<u-form-item label="联系方式" v-if="judgeShow('tableField117-wb014')">
						<u-input v-model="item.wb014" placeholder="联系方式" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb014')
                        "></u-input>
					</u-form-item>

					<u-form-item label="交期" v-if="judgeShow('tableField117-wb015')">
						<u-input v-model="item.wb015" placeholder="交期" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb015')
                        "></u-input>
					</u-form-item>

					<u-form-item label="供应商成本单价" v-if="judgeShow('tableField117-wb016')">
						<u-input v-model="item.wb016" placeholder="" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb016')
                        "></u-input>
					</u-form-item>

					<u-form-item label="网址链接" v-if="judgeShow('tableField117-wb017')">
						<u-input v-model="item.wb017" placeholder="网址链接" :disabled="
                          judgeWrite('tableField117') ||
                            judgeWrite('tableField117-wb017')
                        "></u-input>
					</u-form-item>


				</view>
			</view>
		</u-form>

	</view>
</template>

<script>
	import {
		getPjswa
	} from '@/api/workFlow/flowEngine'
	import {
		getDataInterfaceDataInfo,
		getDictionaryDataSelector,
		getUserAll
	} from '@/api/common'
	import comMixin from '../mixin'
	import {
		getGoodsList,
		getCustomerList,
		Info,
		Create,
		Update
	} from '@/api/apply/order'
	export default {
		name: 'crmOrder',
		mixins: [comMixin],
		data() {
			return {

				hide: false,
				billEnCode: 'OrderNumber',
				dataForm: {},
				lst: [],
				info: {},
				formConf: {},
				id: '',
				buyName: '',
				buyTwoName: '',
				shuizhoLst: [],
				wb018Options: [],
				wa013Name: [],
				wa014Name: [],
			}
		},
		computed: {
			tb010CName(enCode) {
				return enCode => {
					let txt = ''
					let arr = this.shuizhoLst.forEach(item => {
						if (item.enCode == enCode) {
							console.log('item', item)
							txt = item.fullName
						}
					})
					return txt
				}
			},
		},
		methods: {
			// 获取上传状态
			select(e) {
				console.log('选择文件：', e)
			},
			// 获取上传进度
			progress(e) {
				console.log('上传进度：', e)
			},

			// 上传成功
			success(e) {
				console.log('上传成功')
			},

			// 上传失败
			fail(e) {
				console.log('上传失败：', e)
			},
			init(data, id, flowFormContentJson) {
				this.setting = data
				this.id = id
				this.getInfo(data)

			},
			getInfo(data) {
				getPjswa(data.id).then(res => {
					if (res.code == 200) {
						this.info = res.data
						console.log('this.info', this.info)
						this.lst = res.data.tableField117
						this.getUser()
						this.getDictionaryDataSelectorBywb018O()
					}
				})
			},
			getUser() {
				getUserAll().then(res => {
					this.wa013Name = res.data.filter(item => this.info.wa013.includes(item.id)).map(item => item
						.realName);
					this.wa014Name = res.data.filter(item => this.info.wa014.includes(item.id)).map(item => item
						.realName);
				})
			},
			getDictionaryDataSelectorBywb018O(enCode) {
				getDictionaryDataSelector('403687297138106629').then(res => {
					this.shuizhoLst = res.data.list
				})
			},
			selfGetInfo() {
				Info(this.setting.id).then(res => {
					this.dataForm = res.data
					if (this.dataForm.fileJson) {
						this.fileList = JSON.parse(this.dataForm.fileJson)
					}
				})
			},
			selfSubmit() {
				console.log('selfSubmit');
				this.dataForm.status = this.eventType === 'submit' ? 0 : 1
				if (this.eventType === 'save') return this.selfHandleRequest()
				uni.showModal({
					title: '提示',
					content: '您确定要提交当前流程吗？',
					success: res => {
						if (res.confirm) {
							this.selfHandleRequest()
						}
					}
				})
			},
			selfHandleRequest() {
				if (!this.dataForm.id) delete(this.dataForm.id)
				const formMethod = this.dataForm.id ? Update : Create
				formMethod(this.dataForm).then(res => {
					uni.showToast({
						title: res.msg,
						complete: () => {
							setTimeout(() => {
								uni.$emit('refresh')
								uni.navigateBack()
							}, 1500)
						}
					})
				})
			},
			initData() {
				getGoodsList().then(res => {
					this.goodsOptions = res.data.list
				})
				getCustomerList().then(res => {
					this.customerOptions = res.data.list
				})
			},
			selfInit() {
				this.addGoods()
				this.addPlan()
			},
			onChange(e) {
				const user = e[0]
				this.dataForm.salesmanName = user.fullName
			},
			addGoods() {
				const item = {
					goodsId: '',
					goodsCode: '',
					goodsName: '',
					specifications: '',
					unit: '',
					qty: '',
					price: '',
					amount: '',
					discount: null,
					cess: null,
					actualPrice: '',
					actualAmount: '',
					description: ''
				}
				this.dataForm.goodsList.push(item)
			},
			delGoods(index) {
				this.dataForm.goodsList.splice(index, 1)
			},
			addPlan() {
				const item = {
					receivableDate: '',
					receivableRate: '',
					receivableMoney: '',
					receivableMode: '',
					abstract: ''
				}
				this.dataForm.collectionPlanList.push(item)
			},
			delPlan(index) {
				this.dataForm.collectionPlanList.splice(index, 1)
			},
			onGoodsChange(e, i) {
				const goods = e[0]
				this.dataForm.goodsList[i] = {
					goodsId: goods.id,
					goodsCode: goods.code,
					goodsName: goods.text,
					specifications: goods.specifications,
					unit: goods.unit,
					qty: 1,
					price: goods.price,
					amount: goods.price,
					discount: 100,
					cess: 0,
					actualPrice: goods.price,
					actualAmount: goods.price,
					description: ''
				}
				this.$forceUpdate()
			},
			onCustomerChange(e) {
				const customer = e[0]
				this.dataForm.customerName = customer.text
			},
			count(row) {
				//金额 = 数量*单价
				row.amount = this.jnpf.toDecimal(parseFloat(row.price) * parseFloat(row.qty))
				//折扣价 = (单价*折扣)
				var discountPrice = row.price * (row.discount / 100);
				//实际单价 = 折扣价 * (1 + (税率 / 100))
				row.actualPrice = this.jnpf.toDecimal(discountPrice * (1 + (row.cess / 100)));
				//实际金额
				row.actualAmount = this.jnpf.toDecimal(parseFloat(row.actualPrice) * parseFloat(row
					.qty))
				this.$forceUpdate()
			}
		}
	}
</script>